package leetcode;

public class _0206 {
    /**
     * 反转链表
     */
    /**
     * Definition for singly-linked list.
     * public class ListNode {
     *     int val;
     *     ListNode next;
     *     ListNode() {}
     *     ListNode(int val) { this.val = val; }
     *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
     * }
     */
    public class Solution {
        public ListNode reverseList(ListNode head) {
            ListNode pre = null;
            ListNode cur = head;
            while(cur!=null){
                ListNode nxt = cur.next;
                cur.next = pre;
                pre = cur;
                cur = nxt;
            }
            return pre;
        }

        private class ListNode {
            ListNode next;
            int val;
            ListNode(){}
            ListNode(int val){
                this.val=val;
            }
            ListNode(int val,ListNode next){
                this.val = val;
                this.next = next;
            }
        }
    }
}
